package com.bree.erp.jsf.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import javax.faces.context.FacesContext;

import org.apache.commons.lang3.StringUtils;

public final class CurrentInstance {

	private CurrentInstance() {
	}
	
	public static String getYearYY() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		String year = calendar.get(Calendar.YEAR) + "";
		return year.substring(2);
	}

	public static final Long getLongParameter(String param) {
		
		String data = getParameter(param);
		
		if(StringUtils.isEmpty(data)) {
			return null;
		}
		
		return Long.parseLong(data);
		
	}

	public static String getParameter(String param) {

		FacesContext fc = FacesContext.getCurrentInstance();
		Map<String, String> params = fc.getExternalContext()
				.getRequestParameterMap();
		String data = params.get(param);
		
		return data;
	}
	
	public static String printDate(Date date) {
		
		if(date == null) {
			return "";
		}
		
		SimpleDateFormat dt = new SimpleDateFormat("MM/dd/yyyy");
		
		return dt.format(date);
	}

}
